package jason.test.dirtest;

import android.util.Log;

public class Vector3 {
	float x,y,z;
	float[] data;
	public Vector3(float[] f){
		if (f.length != 3){
			Log.e("Vector3", "length is not 3!");			
		} else {
			data = f.clone();
			x = data[0];
			y = data[1];
			z = data[2];
		}		
	}
	public Vector3(float x, float y, float z){
		this.x = x;
		this.y = y;
		this.z = z;		
		data = new float[] {x,y,z};		
	}
	@Override
	public String toString() {
		
		return String.format("\n%.2f\n%.2f\n%.2f",x,y,z);
	}
	
	public Vector3 normolize(){
		double len = getLength();
		x /= len;
		y /= len;
		z /= len;	
		return this;
	}
	public double getLength(){
		return Math.sqrt(x*x+y*y+z*z);
	}
	public Vector3 copy(){
		return new Vector3(x,y,z);	
	}
	public float scalorProduct(Vector3 v){
		return x*v.x + y*v.y + z*v.z;
	}
	public Vector3 scale(float f){
		x *= f;
		y *= f;
		z *= f;
		return this;
	}
	public void add(Vector3 v){
		x += v.x;
		y += v.y;
		z += v.z;
	}
	public Vector3 vectorProduct(Vector3 v) {
		return new Vector3(
				y*v.z - z*v.y,
				z*v.x - x*v.z,
				x*v.y - y*v.x
				);		
	}
	public Vector3 rotate(Vector3 vx, Vector3 vy, Vector3 vz){		
		float xx = scalorProduct(vx);
		float yy = scalorProduct(vy);
		float zz = scalorProduct(vz);
		x = xx;
		y = yy;
		z = zz;
		return this;
	}
	
	public float sum(){
		return x + y + z;
	}
}
